<?php

// we include the functions we will need
include 'functions.php';

// the path/url to the torrent
$torrent_data = bdec(file_get_contents('http://torrents.thepiratebay.org/4402888/T.I.-Paper.Trail.(Explicit.Retail-2008)-%5BNoFS%5D.4402888.TPB.torrent'));

// we need these variables to get the number of users sharing the torrent
$info = strtolower(sha1(benc($torrent_data['info'])));
$scrape = str_replace('announce', 'scrape', $torrent_data['announce']);
$sources = bdec(@file_get_contents($scrape . '?info_hash=' . urlencode(hex2bin($info))));

// let's display the files in the torrent
// since the structure of the torrent is different if it has only one file or more files, we have to count number of files in it
$c = count($torrent_data['info']['files']);
echo '<h2>Files</h2>';

// if it has more then one file do a loop and display all the files; else display the name of the file
if ($c > 1) {
	for ($i = 0; $i < $c; $i++) {
		echo $torrent_data['info']['files'][$i]['path']['0'] . '<br/>';
	}
} else {
	echo $torrent_data['info']['name'] . '<br/>';
}

// let's display the sources
$seeds = $sources['files'][hex2bin($info)]['complete'];
$leechs = $sources['files'][hex2bin($info)]['incomplete'];
$downloads = $sources['files'][hex2bin($info)]['downloaded'];

echo '<h2>Sources</h2>' .
	'<b>Seeds:</b> ' . $seeds . '<br/>' .
	'<b>Leechs:</b> ' . $leechs . '<br/>' .
	'<b>Downloads:</b> ' . $downloads . '<br/>';
	
?>